<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <link rel="stylesheet" type="text/css" media="screen" href="/css/bootstrap.min.css">
    <link rel="stylesheet" type="text/css" media="screen" href="/css/dataTables.bootstrap.min.css">
    <link rel="stylesheet" type="text/css" media="screen" href="/layui/css/layui.css">
    <script type="text/javascript" src="/js/libs/jquery-2.1.1.min.js"></script>
    <link rel="stylesheet" type="text/css" href="/css/bootstrap-select.min.css">
    <script src="/js/bootstrap/bootstrap.min.js"></script>
    <script src="/js/bootstrap/bootstrap-select.min.js"></script>
</head>
<body>
<div class="col-xs-12 col-sm-12 col-md-6 col-lg-6 col-md-offset-2 col-lg-offset-2">
	<form class="form-horizontal" onsubmit="return false" id="form">
		<fieldset>
			<div class='form-group'>
				<label class='col-md-4 control-label'>商品</label>
				<div class='col-md-8'>
					<input class='form-control' type='hidden' name='goodsId' id='goodsId' >
					<input style="width: 90%;float: left;" class='form-control' placeholder='商品' type='text' name='goodsName' id='goodsName' readonly>
					<button style="width: 10%;float: right; height: 32px; line-height: 32px;" class="layui-btn layui-btn-sm"
							onclick="showTableAndFlushFields('fas/goods','goods', '商品', true, false, 'goodsId:id', 'goodsName:name')">
						<i class="layui-icon">&#xe615;</i>
					</button>
				</div>
			</div>
			<div class='form-group' name="pDiv">
				<label class='col-md-4 control-label'>人员</label>
				<div class='col-md-8'>
					<input class='form-control' type='hidden' name='userId' id='userId'>
					<input style="width: 90%;float: left;" class='form-control' placeholder='人员' type='text'
						   name='userName' id='userName' readonly>
					<button style="width: 10%;float: right; height: 32px; line-height: 32px;" class="layui-btn layui-btn-sm"
							onclick="showTableAndFlushFields('user', 'user', '用户', true, false, 'userId:id', 'userName:nickname')">
						<i class="layui-icon">&#xe615;</i>
					</button>
				</div>
			</div>
			<div class='form-group' name="dDiv">
				<label class='col-md-4 control-label'>所属部门</label>
				<div class='col-md-8'>
                    <input class='form-control' type='hidden' name='deptId' id='deptId' >
                    <input style="width: 90%;float: left;" class='form-control' placeholder='所属部门' type='text' name='deptName' id='deptName' readonly>
                    <button style="width: 10%;float: right; height: 32px; line-height: 32px;" class="layui-btn layui-btn-sm"
                            onclick="showSpecialTree('deptId', 'deptName', 'dept', '部门', 'root', 'select','fasDeptTree', true, true)">
                        <i class="layui-icon">&#xe615;</i>
                    </button>
				</div>
			</div>
			<div class='form-group' name="cDiv">
				<label class='col-md-4 control-label'>所属公司</label>
				<div class='col-md-8'>
                    <select class="form-control input-sm selectpicker show-tick" name="companyId" id="companyId"
                            title="所属公司" data-live-search="true"></select>
				</div>
			</div>

			<div class='form-group'>
				<label class='col-md-4 control-label'>总数量</label>
				<div class='col-md-8'>
					<input class='form-control' placeholder='总数量' type='text' name='totalNumber' id='totalNumber'>
				</div>
			</div>

			<div class='form-group'>
				<label class='col-md-4 control-label'>闲置数量</label>
				<div class='col-md-8'>
					<input class='form-control' placeholder='闲置数量' type='text' name='idleNumber' id='idleNumber'>
				</div>
			</div>
			<div class='form-group'>
				<label class='col-md-4 control-label'>备注</label>
				<div class='col-md-8'>
					<textarea class="form-control" placeholder="备注" name="remark" id="remark"></textarea>
				</div>
			</div>

			<div class="form-actions">
				<div class="row" align="center">
					<div class="col-md-12">
					    <!--<button class="btn btn-primary" onclick="window.history.go(-1)">返回</button>-->
						<button class="btn btn-primary" type="submit" onclick="save()">
							<i class="fa fa-save"></i> 保存
						</button>
					</div>
				</div>
			</div>
		</fieldset>
	</form>
</div>
	<script type="text/javascript" src="/js/jq.js"></script>
    <script type="text/javascript" src="/js/plugin/bootstrapvalidator/bootstrapValidator.min.js"></script>
    <script type="text/javascript" src="/js/common.js"></script>
    <script type="text/javascript" src="/layui/layui.js"></script>
    <script type="text/javascript" src="/js/dict.js"></script>
    <script type="text/javascript" src="/js/libs/jquery.ztree.all-3.5.min.js"></script>
    <script type="text/javascript" src="/js/my/ztree-menu.js"></script>

	<script type="text/javascript">
        // 设置验证规则
        var validatorSettings = {
            message: '验证不通过',
            fields: {
                goodsName: {
                    message: '商品名称验证失败',
                    validators: {
                        notEmpty: {
                            message: '商品名称不能为空'
                        }
                    }
                },
                categoryName: {
                    message: '商品类型验证失败',
                    validators: {
                        notEmpty: {
                            message: '商品类型不能为空'
                        }
                    }
                },
                totalNumber: {
                    message: '总数量验证失败',
                    validators: {
                        notEmpty: {
                            message: '总数量不能为空'
                        },numeric: {
                            message: '总数量只能输入数字'
                        }
                    }
                },
                idleNumber: {
                    message: '闲置数量验证失败',
                    validators: {
                        notEmpty: {
                            message: '闲置数量不能为空'
                        },numeric: {
                            message: '闲置数量只能输入数字'
                        }
                    }
                }
            },
            submitHandler: function (validator, form, submitButton) {
                alert("submit");
            }
        };
        layui.use(['layer','laydate'], function(){
            var layer = layui.layer;
            var laydate = layui.laydate;
            laydate.render({
                elem: '#stockTime'
            });
        });
        var type=getUrlParam("type");
	    $(function () {
	        if(type=='p'){

            }else if(type=='d'){
                $("div[name='pDiv']").remove();
            }

            $('#form').bootstrapValidator(validatorSettings);
            showDictSelect('isDeleted', 'boolean', '', '0');
            showDictSelect('companyId', 'company', '', 'beep');
        });
		layui.use(['layer','laydate'], function(){
		    var layer = layui.layer;
		});

		function save() {
			$('#form').bootstrapValidator();
			var bootstrapValidator = $("#form").data('bootstrapValidator');
			bootstrapValidator.validate();
		    if(!bootstrapValidator.isValid()){
			   return;
		    }
		    
		    var formdata = $("#form").serializeObject();

			$.ajax({
				type : 'post',
				url : '/stock/',
				contentType: "application/json; charset=utf-8",  
				data : JSON.stringify(formdata),
				success : function(data) {
					layer.msg("添加成功", {shift: -1, time: 1000}, function(){
                        parent.location.reload();//关闭iFrame
                    });
				}
			});
		}
		
	</script>
</body>
</html>
